<template>
	<view class="box" :style="{height:screenHeight+'px'}">
		<view class="beijingtu">
			<image class="beijingimg" src="https://wine-hjd.oss-cn-beijing.aliyuncs.com/1787459307768623104_b.png"
				mode=""></image>
		</view>
		<view class="logo">
			<image src="../../static/dimg/logo.png" mode=""></image>
			<view>欢迎您，请登录您的账号!</view>
		</view>
		<view class="shuruk">
			<view class="flexs">
				<image src="../../static/dimg/d3.png" mode=""></image>
				<input type="text" placeholder="账号" v-model="account" />
			</view>
			<view class="flexs">
				<image src="../../static/dimg/d2.png" mode=""></image>
				<view class="inputflex">
					<input v-model="password" :password="isshow" placeholder="密码" />
					<view @click="isshow =!isshow" style="width: 80rpx;display: flex;justify-content: center;align-items: center;">
						<uni-icons :type="isshow?'eye-slash' : 'eye'" size="24" ></uni-icons>
					</view>
				</view>
			</view>
			<!-- 		<view>
				<image src="../../static/dimg/d4.png" mode=""></image>
				<input type="number" confirm-type='done' placeholder="验证码" v-model="code" />
				<image class="code" :src="codeimg" mode="" @click="getcode()"></image>
			</view> -->
		</view>
		<button @click="submit">登录</button>
	</view>
</template>

<script>
	import {
		getlogin,
		getText,
		getUserinfo
	} from '@/common/http.api.js';
	export default {
		data() {
			return {
				isshow: true,
				screenHeight: "",
				account: '',
				password: '',
				code: '',
				codeimg: '',
				uuid: ''
			};
		},
		onLoad() {
			this.screenHeight = uni.getSystemInfoSync().windowHeight;
			this.getcode()
		},
		methods: {
			getcode() {
				getText().then(res => {
					this.codeimg = "data:image/gif;base64," + res.img;
					this.uuid = res.uuid
				})
			},
			submit() {
				// if([this.account,this.password].every(function(item,index,array){
				// 	return item == ''
				// })){
				// 	console.log('11111111');
				// }
				if (this.account == '') {
					uni.showToast({
						title: '请输入账号',
						duration: 2000,
						mask: false,
						icon: "none"
					})
				} else if (this.password == '') {
					uni.showToast({
						title: '请输入密码',
						duration: 2000,
						mask: false,
						icon: "none"
					})
				} else {
					let data = {
						password: this.password,
						username: this.account,
					}
					getlogin(data).then(res => {
						if (res.code == 200) {
							uni.setStorageSync('token', res.token)
							getUserinfo().then(res => {
								uni.setStorageSync('user', res.user)
								if (res.roles[0] == 'dailishang') {
									uni.setStorageSync('name', 1)
									uni.redirectTo({
										url: '/pages/tab/home'
									})
								} else if (res.roles[0] == 'hezuodian') {
									uni.setStorageSync('name', 2)
									uni.redirectTo({
										url: '/pages/tab/home'
									})
								} else if (res.roles[0] == 'kefu') {
									uni.setStorageSync('name', 0)
									uni.redirectTo({
										url: '/pages/dier/store'
									})
								} else if (res.roles[0] == undefined) {
									uni.showToast({
										title: '用户暂未分配程序角色',
										duration: 2000,
										mask: false,
										icon: "none"
									})
								}
							})
						} else {
							this.getcode()
						}
					})
				}
			}
		}
	};
</script>

<style lang="scss" scoped>
	.code {
		width: 148rpx !important;
		height: 62rpx !important;
		border-radius: 10rpx;
	}

	input {
		width: 66%;
	}

	.beijingtu {
		width: 100%;
		height: 100%;
		position: absolute;
		z-index: 1;

		.beijingimg {
			width: 100%;
			height: 100%;
		}
	}

	button {
		z-index: 2;
		width: 620rpx;
		height: 85rpx;
		background: linear-gradient(3deg, #E4C085 0%, #F5E1BD 100%);
		border-radius: 43rpx;
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 32rpx;
		color: #302215;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.shuruk {
		z-index: 2;
		margin-top: 120rpx;
		.flexs {
			width: 581rpx;
			height: 41rpx;
			background: #FFFFFF;
			border-radius: 40rpx;
			border: 1px solid #FFFFFF;
			display: flex;
			align-items: center;
			padding: 20rpx;
			margin-bottom: 43rpx;
		}
		.inputflex{
			width: 100%;
			display: flex;
			justify-content: space-between;
			align-items: center;
			input{
				flex: 1;
			}
		}
		image {
			width: 42rpx;
			height: 42rpx;
			margin-right: 10rpx;
		}

	}

	.logo {
		z-index: 2;
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 330rpx;

		image {
			width: 400rpx;
			height: 130rpx;
		}

		view {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #F2DBB4;
			line-height: 48rpx;
			margin-top: 35rpx;
		}
	}
</style>